<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    String imgSrc = basePath + "resources/images/noImage.jpg";
    session.setAttribute("imgSrc", imgSrc);
%>
<!DOCTYPE html>
<html style="background-color: #fff;">
<head>
    <%@include file="../../../../resources/inc/head.jsp" %>
</head>
<body>
<expect-x:tip tipMessage="标识“*”的选项为必填项，其余为选填项。;请按提示信息填写每一个字段" widthClass="full-width-85"/>

<div class="layui-form" lay-filter="layuiadmin-form-systemCorn" id="layuiadmin-form-systemCorn" style="padding: 20px;">

    <input type="hidden" id="id" name="id" value="${productProduct.id}"/>
    <div class="layui-form-item">
        <label class="layui-form-label">产品图片</label>
        <div class="upload-wrapper upload-div " id="layer-photos">
            <div class="upload-item">
                <div class="layui-input-block" style="width: 550px;">
                    <expect-x:webUploader required="true" pickerId="productImg" isLocal="false"
                                          fileList="${productProduct.productImg}" width="140"/>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">轮播图</label>
        <div class="upload-wrapper upload-div ">
            <div class="upload-item">
                <div class="layui-input-block" style="width: auto">
                    <expect-x:webUploader required="true" pickerId="productImgs" multiple="true" isLocal="false"
                                          fileList="${productProduct.productImgs}" width="140"/>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-md6 layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">商品货号</label>
                <div class="layui-input-block">
                    <input type="text" value="${productProduct.productSn}" id="productSn" readonly="true"
                           name="productSn" autocomplete="off" required class="layui-input"></div>
            </div>
        </div>
        <div class="layui-col-md6 layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">商品名称</label>
                <div class="layui-input-block">
                    <input type="text" value="${productProduct.productName}" name="productName" autocomplete="off"
                           required class="layui-input">
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-md6 layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">商品分类</label>
                <div class="layui-input-block">
                    <expect-x:zTree pickerId="productCategoryId" initKey="0" server="manager/productCategory/category.html"
                                    style="metroStyle" width="230" required="false"
                                    defaultVal="${productProduct.productCategoryId}"/>
                    <label class="layui-form-mid layui-word-aux" style="margin-left:40px"> *不选择分类默认为顶级分类</label>
                </div>
            </div>
        </div>
        <div class="layui-col-md6 layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">品牌</label>
                <div class="layui-input-block">
                    <select name="productBrandId">
                        <option value="0">请选择</option>
                    <c:forEach items="${productBrands}" var="productBrand">
                        <option value="${productBrand.id}" ${productProduct.productBrandId==null?'':productProduct.productBrandId==productBrand.id?'selected':''}>${productBrand.productBrandName}</option>
                    </c:forEach>
                    <select>
                </div>
            </div>
        </div>
    </div>


    <div class="layui-row">
        <div class="layui-col-md6 layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">库存</label>
                <div class="layui-input-block">
                    <input type="text" value="${productProduct.productInventoryNumber}"  name="productInventoryNumber" autocomplete="off" required class="layui-input"></div>
            </div>
        </div>
        <div class="layui-col-md6 layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">库存警告</label>
                <div class="layui-input-block">
                    <input type="text" value="${productProduct.productInventoryWarnNumber}" name="productInventoryWarnNumber" autocomplete="off"
                           required class="layui-input">
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-col-md6 layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">销售价格</label>
                <div class="layui-input-block">
                    <input type="text" name="productShopPrice" value="${productProduct.productShopPrice}"
                           autocomplete="off" required class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-col-md6 layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">市场价格</label>
                <div class="layui-input-block">
                    <input type="text" name="productMarketPrice" value="${productProduct.productMarketPrice}"
                           autocomplete="off" required class="layui-input">
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-md6 layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">促销价格</label>
                <div class="layui-input-block">
                    <input type="text" name="productPromotePrice" value="${productProduct.productPromotePrice}"
                           autocomplete="off" required class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-col-md6 layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">促销时间</label>
                <div class="layui-input-block">
                    <input name="productPromoteDate" type="text" class="layui-input" id="productPromoteDate" placeholder=" - " >
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-col-md2 layui-col-xs3">
            <div class="layui-form-item">
                <label class="layui-form-label">是否在售</label>
                <div class="layui-input-block">
                    <input type="checkbox" ${productProduct.productIsOnSale==1?'checked':''} name="productIsOnSale"
                           lay-skin="switch" lay-text="是|否">
                </div>
            </div>
        </div>
        <div class="layui-col-md2 layui-col-xs3">
            <div class="layui-form-item">
                <label class="layui-form-label">是否新品</label>
                <div class="layui-input-block">
                    <input type="checkbox" ${productProduct.productIsNew==1?'checked':''} name="productIsNew"
                           lay-skin="switch" lay-text="是|否">
                </div>
            </div>
        </div>
        <div class="layui-col-md2 layui-col-xs3">
            <div class="layui-form-item">
                <label class="layui-form-label">是否精品</label>
                <div class="layui-input-block">
                    <input type="checkbox" ${productProduct.productIsBest==1?'checked':''} name="productIsBest"
                           lay-skin="switch" lay-text="是|否">
                </div>
            </div>
        </div>
        <div class="layui-col-md2 layui-col-xs3">
            <div class="layui-form-item">
                <label class="layui-form-label">是否热销</label>
                <div class="layui-input-block">
                    <input type="checkbox" ${productProduct.productIsHot==1?'checked':''} name="productIsHot"
                           lay-skin="switch" lay-text="是|否">
                </div>
            </div>
        </div>
        <div class="layui-col-md2 layui-col-xs3">
            <div class="layui-form-item">
                <label class="layui-form-label">是否促销</label>
                <div class="layui-input-block">
                    <input type="checkbox" ${productProduct.productIsPromote==1?'checked':''} name="productIsPromote"
                           lay-skin="switch" lay-text="是|否">
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商品关键字</label>
        <div class="layui-input-block">
            <input type="text" name="productKeywords"
                   value="${productProduct.productKeywords==null?'假一赔十 | 7天无忧退货 | 72小时发货':productProduct.productKeywords}"
                   autocomplete="off" required class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商品描述</label>
        <div class="layui-input-block">
            <textarea name="productDesc" style="resize:none" required class="layui-textarea"
                      value="${productProduct.productDesc}">${productProduct.productDesc}</textarea>
        </div>
    </div>
    <%--<div class="layui-form-item">--%>
    <%--<label class="layui-form-label">图片详情</label>--%>
    <%--<expect-x:webUploader pickerId="productLongDesc" multiple="true"   fileList="${productProduct.productLongDesc}" isLocal="false" width="90" />--%>
    <%--</div>--%>
    <div class="layui-form-item">
        <label class="layui-form-label">图片详情</label>
        <div class="upload-wrapper upload-div ">
            <div class="upload-item">
                <div class="layui-input-inline" style="width: auto;">
                    <expect-x:webUploader required="true" multiple="true" pickerId="productLongDesc" isLocal="false"
                                          fileList="${productProduct.productLongDesc}" width="140"/>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="LAY-submit" id="LAY-submit" value="确认">
    </div>
</div>


<%@include file="../../../../resources/inc/footer.jsp" %>

<script>

    $(document).ready(function () {
        var timestamp = new Date().getTime()
        if ($('#productSn').val().length == 0) {
            $('#productSn').val(timestamp)
        }
    });

    function selectCardType(type, obj) {
        $(".cardTypeBtn").addClass("layui-btn-primary");
        $(obj).removeClass("layui-btn-primary");
        $("#cardType").val(type);
    }

    $.fn.serializeObject = function () {
        var obj = {};
        var count = 0;
        $.each(this.serializeArray(), function (i, o) {
            var n = o.name, v = o.value;
            count++;
            obj[n] = obj[n] === undefined ? v
                : $.isArray(obj[n]) ? obj[n].concat(v)
                    : [obj[n], v];
        });
        //obj.nameCounts = count + "";//表单name个数
        return JSON.stringify(obj);
    };
    layui.config({
        base: '<%=basePath%>resources/lib/layuiAdmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form','laydate'], function () {
        var $ = layui.$
            , form = layui.form,
             laydate = layui.laydate;
        //日期时间范围
        laydate.render({
            elem: '#productPromoteDate'
            ,type: 'datetime'
            ,range: true
            ,trigger: 'click' //采用click弹出
            ,position: 'fixed'
            <c:if test="${productProduct.productPromoteStartDate!=null&&productProduct.productPromoteEndDate!=null}">
            ,value:'${productProduct.productPromoteStartDate} - ${productProduct.productPromoteEndDate}'
            </c:if>

        });
    })

    function createSubmit() {
        var layer = layui.layer;
        var submitID = 'LAY-submit';
        layui.form.on('submit(' + submitID + ')', function (data) {
            var formData = data.field;
            delete formData["productCategoryIdTree"];
            if (formData.productCategoryId == ":") {
                formData.productCategoryId = 0;
            }
            formData.productIsBest = (formData.productIsBest == 'on' ? '1' : 0);
            formData.productIsOnSale=(formData.productIsOnSale=='on'?'1':0);
            formData.productIsHot = (formData.productIsHot == 'on' ? '1' : 0);
            formData.productIsNew = (formData.productIsNew == 'on' ? '1' : 0);
            formData.productIsPromote = (formData.productIsPromote == 'on' ? '1' : 0);

            var promoteDate = formData.productPromoteDate.toString();
            var date= promoteDate.split(" - ")
            formData.productPromoteStartDate=date[0];
            formData.productPromoteEndDate=date[1];

            if (formData.id == "" || formData.id == null) {
                $.ajax({
                    url: '<%=basePath%>manager/productProduct/create.html',
                    type: "POST",
                    data: formData,
                    dataType: "JSON",
                    success: function (data) {
                        layer.closeAll('loading');
                        data = JSON.parse(data);
                        if (data.success) {
                            layer.msg("创建成功,1秒后跳转")
                            setTimeout(function () {
                                window.parent.location.reload(); //刷新父页面
                                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                parent.layer.close(index);
                            }, 1000);
                        } else {
                            layer.msg(data.message, {icon: 5});
                        }
                    }
                });
            } else {
                $.ajax({
                    url: "<%=basePath%>manager/productProduct/update/" + formData.id + ".html",
                    type: "POST",
                    data: formData,
                    dataType: "JSON",
                    success: function (data) {
                        layer.closeAll('loading');
                        data = JSON.parse(data);
                        if (data.success) {
                            layer.msg("修改成功,1秒后跳转");
                            setTimeout(function () {
                                window.parent.location.reload(); //刷新父页面
                                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                parent.layer.close(index);
                            }, 1000);
                        } else {
                            layer.msg(data.message, {icon: 5});
                        }
                    }
                });
            }
        })
        $("#" + submitID).trigger('click');
    }
</script>
</body>
</html>
